package cn.tedu.clyback.RolePermission.controller;

import cn.tedu.clyback.RolePermission.pojo.vo.RolePermissionVO;
import cn.tedu.clyback.RolePermission.service.RolePermissionService;
import cn.tedu.clyback.base.response.JsonResult;
import cn.tedu.clyback.role.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/rolepermission")
public class RolePermissionController {
    @Autowired
    RolePermissionService rolePermissionService;
    @PostMapping("/adduserper/{roleId}/{permissionId}")
    public JsonResult insertPermission(@PathVariable Integer roleId, @PathVariable Integer permissionId) {
        log.debug("开始处理【根据角色id添加用户】的请求，参数：{} ,{}", roleId, permissionId);
        rolePermissionService.insertPermission(roleId, permissionId);
        return JsonResult.ok();
    }

    @PostMapping("/deleteuserper/{roleId}/{permissionId}")
    public JsonResult deleteUserPermission(@PathVariable Integer roleId, @PathVariable Integer permissionId) {
        log.debug("开始处理【根据角色id删除用户】的请求，参数：{} ,{}", roleId, permissionId);
        rolePermissionService.deleteUserPermission(roleId, permissionId);
        return JsonResult.ok();
    }

    @GetMapping("/select/{roleId}")
    public JsonResult selectUserByRoleId(@PathVariable Integer roleId) {
        log.debug("开始处理【根据角色已有权限】的请求，参数：{}", roleId);
        HashSet<RolePermissionVO> set = rolePermissionService.selectUserByRoleId(roleId);
        log.debug("查询结果：{}", set);
        return JsonResult.ok(set);
    }

    @PostMapping("/deletepermission/{roleId}/{permissionId}")
    public JsonResult deletePermission(@PathVariable Integer roleId, @PathVariable Integer permissionId){
        log.debug("开始处理【根据角色id和权限id删除权限】的请求，参数：{} ,{}", roleId, permissionId);
        rolePermissionService.deletePermission(roleId,permissionId);
        return JsonResult.ok();
    }


}